package com.fdl.testConnection;

import java.sql.*;

/**
 *测试oracle连接
 * project: hb-intra
 * Date:2010-7-27
 * @version  1.0
 * Company: 33e9
 * @author zhangYong.huang
 */

public class OracleConnection {

	public static void main(String[] args) {
		String sql;
		Statement stmt = null;
		ResultSet rs = null;
		Connection conn = null;
		sql = "select * from test";// 使用的数据表

		try {
			Class.forName("oracle.jdbc.driver.OracleDriver");// 注册驱动

			try {
				conn = DriverManager.getConnection(
						"jdbc:oracle:thin:@10.0.11.60:1521:devdb", "hb", "hb");
				// 建立连接的语句，注意用的test数据库，用户为root，密码为空，这个根据实际调整
			} catch (SQLException ex1) {// catch出错
			}
			stmt = conn.createStatement();
			rs = stmt.executeQuery(sql);// 执行sql语句，rs是指向其当前数据行的指针
			while (rs.next()) {
				System.out.println(rs.getString("value"));												// ，下类同
			}
		} catch (ClassNotFoundException ex) {
			System.out.println("no driver is f d!\n" + ex);
		} catch (SQLException ex) {
			System.out.println("database connection is wrong!" + ex);
		} finally {
			try {
				rs.close();
				stmt.close();
				conn.close();
			} catch (Exception ex) {
				System.out.println("Close error!");
			}
		}
	}

}
